package com.neulogistics.core.substation.api.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blackto.lib.mediat.core.IMediator;
import com.neulogistics.core.substation.api.application.command.CreateSubstationCommand;
import com.neulogistics.core.substation.api.application.command.CreateTaskOrderCommand;
import com.neulogistics.core.substation.api.application.command.SubstationIdCommand;
import com.neulogistics.core.substation.api.application.query.ISubstationQueryService;
import com.neulogistics.core.substation.api.application.query.SubstationQuery;
import com.neulogistics.core.substation.api.application.viewmodel.SubstationTreeViewModel;
import com.neulogistics.core.substation.api.application.viewmodel.SubstationViewModel;
import com.neulogistics.infrastructure.common.serviceresult.BaseResponse;
import com.neulogistics.infrastructure.common.serviceresult.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import java.util.List;

@RestController
@Api(tags = "分站管理")
@RequestMapping("/substation")
public class SubstationController {
    @Resource
    private IMediator mediator;

    @Resource
    ISubstationQueryService substationQueryService;

    @ApiOperation("创建分站")
    @PostMapping("/create")
    public BaseResponse<String> create(@RequestBody @Validated @NotNull CreateSubstationCommand command){
        // 已校验数据格式

        return mediator.send(command);
    }

    @ApiOperation("根据id查询分站")
    @PostMapping("/get")
    public BaseResponse<SubstationViewModel> get(@RequestBody @NotNull SubstationIdCommand command){
        // 已校验数据格式

        SubstationViewModel substationViewModel = substationQueryService.getById(command.substationId);
        return ResultUtils.success(substationViewModel);
    }

    @ApiOperation("分页查询分站")
    @PostMapping("/page")
    public BaseResponse<Page<SubstationViewModel>> page(@RequestBody @NotNull @Validated SubstationQuery substationQuery){
        // 已校验数据格式

        Page<SubstationViewModel> viewModelPage = substationQueryService.page(substationQuery);
        return ResultUtils.success(viewModelPage);
    }

    @ApiOperation("查询分站名称和id")
    @GetMapping("/list")
    public BaseResponse<List<SubstationTreeViewModel>> list(){
        // 已校验数据格式

        List<SubstationTreeViewModel> viewModels = substationQueryService.list();
        return ResultUtils.success(viewModels);
    }
}
